package com.test.ayi.test.competablefuture;

import java.util.Objects;
import java.util.concurrent.CompletableFuture;

public class CFtest4Handle {
    public static void main(String[] args) throws InterruptedException {

        CompletableFuture<String> handle = CompletableFuture.supplyAsync(() -> {
                    if (Math.random() > 0.5) throw new RuntimeException("小强出现！");
                    return "香喷喷";
                })
                .handle((result, throwable) -> {
                    if (Objects.nonNull(throwable)) return "小强跑了";
                    return result;
                });

        System.out.println(handle.join());


    }
}
